package com.oscar.web.service;

import com.oscar.web.dao.UserBookBuyRepository;
import com.oscar.web.dao.UserBookEvaluateRepository;
import com.oscar.web.domain.buy;
import com.oscar.web.domain.rating;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserBookBuyService {

    @Autowired
    private UserBookBuyRepository userBookBuyRepository;

    public void buyBook(buy userBookBuy){
        if(userBookBuyRepository.existsByUserIdAndBookId(userBookBuy.getUserId(),userBookBuy.getBookId())){
            userBookBuy.setNum(userBookBuyRepository.getByUserIdAndBookId(userBookBuy.getUserId(),userBookBuy.getBookId()).getNum()+1);
        }else{userBookBuy.setNum(1);}
        userBookBuyRepository.save(userBookBuy);
    }
}
